package com.example.petcare.controller.provider;

import com.example.petcare.pojo.Goods;
import com.example.petcare.pojo.Pet;
import com.example.petcare.pojo.Result;
import com.example.petcare.service.GoodsService;
import com.example.petcare.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController//标记为控制器类,并且返回json数据
@RequestMapping("/provider")//请求路径
@Slf4j
public class GoodsController {

    @Autowired
    private GoodsService goodsservice;

    // 添加增值商品
    @PostMapping("/addGoods")
    public Result addGoods(@RequestBody Goods goods) {
        goodsservice.addGoods(goods);
        return Result.success();
    }

    // 修改增值商品
    @PostMapping("/updateGoods")
    public Result updateGoods(@RequestBody Goods goods) {
        goodsservice.updateGoods(goods);
        return Result.success();
    }

    // 查看增值商品列表
    @GetMapping("/getGoodsList")
    public Result<List<Goods>> GoodsList() {

        List<Goods> glist = goodsservice.getGoodsList();

        return Result.success(glist);
    }


    // 删除增值商品
    @DeleteMapping("/deleteGoods")
    public Result deleteGoods(@RequestParam("gId") Integer gId) {
        goodsservice.deleteGoods(gId);
        return Result.success();
    }

    // 修改商品上下架状态
    @PostMapping("/updateGoodsStatus")
    public Result updateGoodsStatus(@RequestParam("gId") Integer gId, @RequestParam("isOnSale") Boolean isOnSale) {
        goodsservice.updateGoodsStatus(gId, isOnSale);
        return Result.success();
    }


}
